import messageManager from "@/manager/messageManager.js";
import { useUserStores } from "@/stores/index.js";
const userStores = useUserStores();

function test_ClickEvent(index) {
  messageManager.add({
    text: "".padStart(index + 1, "m"),
    color: "red",
  });
}

function createConfig_ClickEvent() {
  userStores
    .createConfigAsyncAction()
    .then((res) => {
      messageBox.show({
        color: "green",
        text: "create config OK!",
      });
    })
    .catch((res) => {
      messageBox.show({
        color: "red",
        text: res.data.message,
      });
    });
}

function login_ClickEvent(action) {
  var input = document.querySelector("#userCodeInput");
  if (input.value) {
    userStores
      .loginAsyncAction(input.value)
      .then((res) => {
        messageBox.show({
          color: "green",
          text: "Login OK!",
        });
        action();
      })
      .catch((res) => {
        messageBox.show({
          color: "red",
          text: res,
        });
      });
  }
}

function logOff_ClickEvent(action) {
  userStores.logOffAction();
  action();
}

function gtoTelegram_ClickEvent() {
  const url = "https://t.me/+XLI54thTAGQ5Yzg1";
  window.open(url);
}

function randomOrder_ChangeEvent(data) {
  userStores.config.randomOrder = data ? 1 : 0;
}

export {
  test_ClickEvent,
  createConfig_ClickEvent,
  login_ClickEvent,
  logOff_ClickEvent,
  gtoTelegram_ClickEvent,
  randomOrder_ChangeEvent,
};
